<?php
declare (strict_types = 1);

namespace app\validate\home;

use app\common\model\User;
use think\Validate;

class Login extends Validate
{
    /**
     * 定义验证规则
     * 格式：'字段名' =>  ['规则1','规则2'...]
     *
     * @var array
     */
    protected $rule = [
        'user_name'=>  'require|max:20|unique:'.User::class,
        'pwd'=>'require|max:200',
//        'phone'=>'max:11',
        'used'=>'require|max:200',
    ];

    /**
     * 定义错误信息
     * 格式：'字段名.规则名' =>  '错误信息'
     *
     * @var array
     */
    protected $message  =   [
        // 'user_name.require' => '账号必填',
        // 'user_name.max'     => '账号最多20字',
        // 'user_name.unique'  => '账号已存在',
        'pwd.require'       => '密码必填',
        'pwd.max'           => '密码最多200字',
        'phone.max'         => '手机号只能11字',
        'phone.unique'      => '手机号已存在',
        'used.require'      => '旧密码必填',
        'used.max'          => '旧密码最多200字',
    ];

    /**
     * 验证场景
     * @var \string[][]
     */
    protected $scene  = [
        'login'=>['user_name','pwd'],//登陆
        'register_auto'=>['phone'],//游客注册
        'register_user'=>['phone','pwd'],//用户手动注册
        'forget'=>['phone','pwd'],//忘记密码
        'edit_pwd' =>['pwd','phone','user_name'],//修改密码
    ];

    public function sceneLogin()
    {
        return $this->only(['phone','pwd'])->remove('phone','unique'); // TODO: Change the autogenerated stub
    }
}
